package com.example.springbatchdemo.kafka.producer;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;


public class CustomerProducer {
    public static void main( String[] args ) {


        /**
         * kafka的相关配置信息
         */
        Properties props = new Properties();
        // kafka集群
        //props.put("bootstrap.servers", "192.168.81.20:9092");
        props.put("bootstrap.servers", "http://192.168.81.20:9092");
        // 应答级别
        props.put("acks", "all");
        // 重试次数
        props.put("retries", 0);
        // 批量大小
        props.put("batch.size", 16384);
        // 延迟时间
        props.put("linger.ms", 1);
        // 缓存
        props.put("buffer.memory", 33554432);
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

        Producer<String, String> producer = new KafkaProducer<>(props);
        for (int i = 0; i < 100; i++)
            producer.send(new ProducerRecord<String, String>("first", Integer.toString(i), Integer.toString(i)));

        producer.close();
    }
}
